import React from "react";
import { Router, Route, Switch } from "dva/router";
import { RouterAPI } from "dva";
import Layout from "../pages/layout/index";
import Login from "../pages/login/index";
import zhCN from "antd/locale/zh_CN";
import { ConfigProvider } from "antd";
import { Iprops } from "../type/router";

interface RouterItem {
  path: string;
  comopnent: React.ReactNode;
  children?: RouterItem[];
}
const RouterList: RouterItem[] = [
  {
    path: "/login",
    comopnent: <Login />,
  },
  {
    path: "/",
    comopnent: <Layout />,
  },
];
export default function RouterMp(props: Iprops) {
  const { api } = props;
  return (
    <div>
      {
        // 处理全局格式化
        <ConfigProvider locale={zhCN}>
          <Router history={api.history}>
            <Switch>
              {RouterList.map((ite) => {
                return (
                  <Route path={ite.path} key={ite.path}>
                    {ite.comopnent}
                  </Route>
                );
              })}
            </Switch>
          </Router>
        </ConfigProvider>
      }
    </div>
  );
}
